package com.tgu.controller;


import com.tgu.entity.request.OrderReq;
import com.tgu.entity.request.TakeOrderReq;
import com.tgu.entity.request.UserCancelReq;
import com.tgu.service.IOrdersService;
import com.tgu.utils.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * @author duruikun
 * @email 136989204@qq.com
 * @date 2022-08-17 09:44:03
 */
@RestController
@RequestMapping("portal/orders")
public class OrdersController {

    @Autowired
    private IOrdersService ordersService;


    @RequestMapping("/postOrder")
    public Result postOrder(@RequestBody OrderReq order) {
        return ordersService.postOrderByEntity(order);
    }

    @GetMapping("/market/{pageNumb}/{option1}/{option2}")
    public Result market(@PathVariable Integer pageNumb, @PathVariable Integer option1, @PathVariable String option2) {
        return ordersService.getMarketPage(pageNumb, option1, option2);
    }

    @GetMapping("/person/{id}")
    public Result person(@PathVariable String id) {
        return ordersService.getByPerson(id);
    }

    @PostMapping("/rider/takeOrder")
    public Result takeOrder(@RequestBody TakeOrderReq takeOrderReq) {
        return ordersService.takeOrderOne(takeOrderReq);
    }

    @GetMapping("/rider/{id}")
    public Result getSendOrder(@PathVariable String id) {
        return ordersService.getByRider(id);
    }

    @PostMapping("/info")
    public Result getOrderById(@RequestBody TakeOrderReq takeOrderReq) {
        return ordersService.getOrderById(takeOrderReq);
    }

    // 本来要用PUT请求，但是不行，参考网址：https://blog.csdn.net/weixin_53458434/article/details/118673550
    @PostMapping("/finish")
    public Result finish(@RequestBody TakeOrderReq takeOrderReq) {
        return ordersService.finishOrder(takeOrderReq);
    }

    @PostMapping("/cancel/user")
    public Result userCancelOrder(@RequestBody UserCancelReq cancelReq) {
        return ordersService.userCancelOrder(cancelReq);
    }

    @PostMapping("/abandon/rider")
    public Result riderCancelOrder(@RequestBody UserCancelReq cancelReq) {
        return ordersService.riderAbandonOrder(cancelReq);
    }
}
